package Track6;

import track5.MyThread;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;

public class MyCallable implements Callable<Integer> {
    List<Integer> list;
    List<Integer> box = new ArrayList<>();

    public MyCallable(List<Integer> list) {
        this.list = list;
    }

    @Override
    public Integer call() throws Exception {
        while (true) {
            synchronized (MyCallable.class) {
                //判断是否抽完
                if (list.size() == 0) {
                    break;
                }else {
                    //继续抽奖
                    Collections.shuffle(list);
                    //拿到第一个值然后删掉
                    Integer price = list.remove(0);
                    box.add(price);
                }
            }
            Thread.sleep(10);
        }
        //集合的最大值返回
        if (box.size()==0){
            return null;
        }else {
            return Collections.max(box);
        }
    }
}